package com.shenbianyun;

import com.shenbianyun.bosskgpay.utils.SnowflakeIdGeneratorFactory;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author ：张一凡
 * @date ：2024年02月27日 11:41:13
 * @description：
 */
public class a123 {


    public static String getToken(String url) {
        String token = null;
        String regex = "token=([^&]*)";

        // 使用正则表达式匹配 token 值
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(url);

        if (matcher.find()) {
            token = matcher.group(1);
        }

        return token;
    }


    public static String generatePhoneNumber() {
        // ⽣成⼿机号的前三位
        int prefix = 130 + (int) (Math.random() * 10);
        // ⽣成⼿机号的后8位
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 8; i++) {
            sb.append(random.nextInt(10));
        }
        int suffix = Integer.parseInt(sb.toString());
        // 组合前三位和后8位⽣成完整⼿机号
        String phoneNumber = prefix + String.format("%08d", suffix);
        // 正则表达式验证⼿机号格式
        //String regex = "^1[3|4|5|7|8|9][0-9]{9}$";
        //boolean isValid = phoneNumber.matches(regex);
        //System.out.println("随机⽣成的⼿机号：" + phoneNumber);
        //System.out.println("⼿机号是否合法：" + isValid);
        return phoneNumber;
    }

    public static void main(String[] args) {
        String resData = "https://testconfirm.serviceshare.com/pages/budSign.html#/?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWxhdGlvbklkIjoiMjQiLCJlbnRlcnByaXNlSWQiOiIxNjQzMDA0MjExNTY5NDM5IiwiZXhwIjoxNzE2NzgwODkzfQ.F20M-bNbebw15tSRYZLYBpUnj8XjvCPKeqpgSctbd6o&redirectUrl=null";
        String a = getToken(resData);
        System.out.println(a);


        // 生成随机手机号
        String phoneNumber = generatePhoneNumber();

        System.out.println("随机生成的手机号: " + phoneNumber);

        String s = SnowflakeIdGeneratorFactory.getInstance().nextId().toString();
        System.out.println(s);
        s.substring(0, 8);
        System.out.println(SnowflakeIdGeneratorFactory.getInstance().nextId().toString().substring(0, 8));

    }
}
